package org.hzero.order.api.controller.v1;

/**
 * @author xiuiqng.Yang-Estelle-양수청
 * @date 2019/8/7 8:56
 */

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.hzero.core.util.Results;
import org.hzero.order.config.SwaggerTags;
import org.hzero.order.domain.entity.Customer;
import org.hzero.order.domain.repository.CustomerRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.choerodon.core.domain.Page;
import io.choerodon.core.iam.ResourceLevel;
import io.choerodon.mybatis.pagehelper.domain.PageRequest;
import io.choerodon.swagger.annotation.Permission;

/**
 * API接口
 */
@Api(tags = SwaggerTags.CUSTOMER)
@RestController("customerController.v1")
@RequestMapping("/v1/{organizationId}/customers")
public class CustomerController {

    @Autowired
    private CustomerRepository customerRepository;

    @ApiOperation(value = "根据客户编号和客户名称查询客户")
    @Permission(level = ResourceLevel.SITE, permissionLogin = true)
    @GetMapping
    public ResponseEntity<Page<Customer>> queryCompanyList(
            @RequestParam String companyNumber,
            String customerNumber,
            String customerName,
            PageRequest pageRequest){
        Customer customer = new Customer();
        customer.setCustomerNumber(customerNumber);
        customer.setCustomerName(customerName);
        return Results.success(customerRepository.pageCustomer(customer, companyNumber, pageRequest));
    }

    @ApiOperation(value = "LOV选择客户名称(查询值集列表)")
    @Permission(level = ResourceLevel.SITE, permissionLogin = true)
    @GetMapping("/name")
    public ResponseEntity<Page<Customer>> queryCustomerName(PageRequest pageRequest){

        return Results.success(customerRepository.pageCustomerName(pageRequest));
    }
}
